package com.hsylient.common.response;

import com.hsylient.common.enums.ResponseStatus;
import lombok.AllArgsConstructor;
import lombok.Data;

@Data
@AllArgsConstructor
public class BaseResponse<T> {

    private int code;
    private String message;
    private T data;
    private long timestamp;

    public BaseResponse() {
        this.timestamp = System.currentTimeMillis();
    }

    public BaseResponse(ResponseStatus status, T data) {
        this.code = status.getCode();
        this.message = status.getMessage();
        this.data = data;
        this.timestamp = System.currentTimeMillis();
    }

    public BaseResponse(int code, String message, T data) {
        this.code = code;
        this.message = message;
        this.data = data;
        this.timestamp = System.currentTimeMillis();
    }

    // 成功响应
    public static <T> BaseResponse<T> success(T data) {
        return new BaseResponse<>(ResponseStatus.SUCCESS, data);
    }

    public static <T> BaseResponse<T> success() {
        return success(null);
    }

    // 失败响应
    public static <T> BaseResponse<T> error(ResponseStatus status) {
        return new BaseResponse<>(status, null);
    }

    public static <T> BaseResponse<T> error(int code, String message) {
        return new BaseResponse<>(code, message, null);
    }
}
